﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using com.tiyma.common;
using com.tiyma.components;
using com.tiyma.model;

namespace com.tiyma.web.book
{
    public partial class Chapter : BasePage
    {
        string m_chapter_id = string.Empty;
        public int m_site_id = 0;

        public string m_chapter_url = string.Empty;
        public string m_pre_chapter_id = string.Empty;
        public string m_next_chapter_id = string.Empty;
        public string m_book_id = string.Empty;
        string m_book_name = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            m_chapter_id = Request["chapterId"];
            if (!int.TryParse(Request["siteId"], out m_site_id))
                m_site_id = 0;
            m_book_name = Request["n"];

            BindChapter();
        }

        private void BindChapter()
        {
            try
            {
                BookManager t_book_mgr = new BookManager();

                ChapterInfo t_chapter = t_book_mgr.GetChapterInfo(m_chapter_id, m_site_id);

                if (t_chapter != null)
                {
                    m_chapter_url = t_chapter.ChapterUrl;
                    m_pre_chapter_id = t_chapter.PreChapterId;
                    m_next_chapter_id = t_chapter.NextChapterId;
                    m_book_id = t_chapter.BookId;
                    Page.Title = string.Format("体验码_{0}_{1}_来自{2}", t_chapter.ChapterName,m_book_name, Consts.GetSiteName(m_site_id));

                    CookieManager.SetChapterReadCookie(t_chapter.BookId, m_book_name, t_chapter.ChapterId, t_chapter.ChapterName, m_site_id);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("绑定章节内容失败" + ex.ToString());

            }
        }
    }
}
